package com.mission.game.playgame;

import android.view.View;
import android.widget.EditText;

import com.mission.game.R;
import com.mission.game.utils.Task;
import com.mission.game.utils.TextTask;

public class PlayTextTask extends PlayAbstractTask {

	private EditText _responseView;

	@Override
	protected int getNameInput() {
		return R.id.play_text_name;
	}

	@Override
	protected int getDescriptionInput() {
		return R.id.play_text_description;
	}

	@Override
	protected void setSpecificFields() {
		_responseView = (EditText) findViewById(R.id.play_text_response_input);
		_responseView.setText(((TextTask) _task).getUserAnswer());
	}

	@Override
	protected int getContentView() {
		return R.layout.play_text_task;
	}

	@Override
	public void onBackToMissionClicked(View v) {
		String correctAnswer = ((TextTask) _task).getCorrectAnswer();
		String userAnswer = _responseView.getText().toString();
		if (correctAnswer.toLowerCase().trim()
				.equals(userAnswer.toLowerCase().trim())) {
			_task.setStatus(Task.Status.COMPLETED);
		} else {
			_task.setStatus(Task.Status.REJECTED);
		}
		if (userAnswer != null) {
			((TextTask) _task).setUserAnswer(userAnswer);
		}
		getIntent().putExtra("task", _task);
		setResult(RESULT_OK, getIntent());
		finish();
	}

}
